<?php
# !!!!!!!!!! DON'T MAKE ANY CHANGE IF YOU DON'T KNOW WHAT YOU'RE DOING !!!!!!!!!!
// --------------------------------------------------------------------------------------------------------------
// File Name              :	brands.php
// Last Modification Time :	2008-02-01 24:00
// Last Modified by       :	turker (turker.biz@gmail.com)
// list of modifications  :
//
//	- 2008-02-01 turker
//		* 24:00 file created.
//
// --------------------------------------------------------------------------------------------------------------
if (eregi("brands.php",$_SERVER['PHP_SELF'])) {
	header ("Location:../index.php");
	exit;
}

$id=getID($BRANDS_TABLE);
if (!$id) {
  header ("Location:$SITE_URL/index.php?page=404");
	exit;
}

$page=findPage();
$start=($page-1)*$ITEMS_PER_CATEGORY;
?>
<!--div:icerik -->
    <div id="icerik">
    <p>
<?php
/*
$active="and $BRANDS_TABLE.active='1' and $EXCHANGES_TABLE.active='1'";
if (isAdmin()) $active='';

$sql="select
$ITEMS_TABLE.*,
$EXCHANGES_TABLE.name as ename,$EXCHANGES_TABLE.exchange,
$ITEM_PRICES_TABLE.price,$ITEM_PRICES_TABLE.active as price_active,$ITEM_PRICES_TABLE.info as pinfo,$ITEM_PRICES_TABLE.campaign,$ITEM_PRICES_TABLE.campaign_price,$ITEM_PRICES_TABLE.item_id
from
$ITEMS_TABLE,$ITEM_CATS_TABLE,$BRANDS_TABLE,$ITEM_PRICES_TABLE,$EXCHANGES_TABLE
where
$ITEM_CATS_TABLE.item_id=$ITEMS_TABLE.id and
$BRANDS_TABLE.id='$id' and $BRANDS_TABLE.id=$ITEMS_TABLE.brand_id $active and
$ITEM_PRICES_TABLE.item_id=$ITEMS_TABLE.id and $ITEM_PRICES_TABLE.exchange_id=$EXCHANGES_TABLE.id and $ITEMS_TABLE.lang='$SITE_DEF_LANG' and
group by $ITEM_PRICES_TABLE.item_id order by $ITEMS_TABLE.`order` asc limit $start,$ITEMS_PER_CATEGORY";
*/
$active=" and bt.active='1'";
if (isAdmin()) $active='';
$sql="select
    it.*,
    ip.price, ip.info as p_info, ip.campaign, ip.campaign_price, ip.active as p_active,
    ex.name as ex_name, ex.exchange, ex.active as e_active
    from $BRANDS_TABLE as bt,$ITEMS_TABLE as it
    left join $ITEM_PRICES_TABLE as ip on it.id=ip.item_id
    left join $EXCHANGES_TABLE as ex on ex.id=ip.exchange_id
    where bt.id='$id' and bt.id=it.brand_id $active and it.lang='$SITE_DEF_LANG'
    group by it.id order by it.`order` asc limit $start,$ITEMS_PER_CATEGORY";

$q=$mysql->query($sql);
if ($mysql->numRows($q)>0) {
  # pagination start
  $active=" and active='1'";
  if (isAdmin()) $active='';
  $pages=array();
  $query=$mysql->query("select count(id) as total from $ITEMS_TABLE where brand_id='$id' $active");
  $total=$mysql->result($query,'total');
  $total_page=round($total/$ITEMS_PER_CATEGORY);
  for ($i=1;$i<=$total_page;$i++) {
    if ($i!=$page) {
      if (!$SITE_SEO) $pages[]="<a href=\"index.php?page=brands&id=$id&p=$i\" title=\"".$_LANG['general']['page']." $i\">$i</a>";
      else $pages[]="<a href=\"$SITE_URL/brands/$bname/$i\" title=\"".$_LANG['general']['page']." $i\">$i</a>";
    }
    else $pages[]=$i;
  }
  if (count($pages)>1) {
    $pages=implode(' | ',$pages);
    $pages='<div id="pagination">'.$pages.'</div><br />';
  }
  else $pages='';
  # pagination end

  # find brand name start
  $query=$mysql->query("select title,name from $BRANDS_TABLE where id='$id'");
  $btitle=$mysql->result($query,'title');
  $bname=$mysql->result($query,'name');
  $btitle=$prep->html($btitle);
  # find brand name end

  echo "<h1>$btitle ".$_LANG['brands']['title']."</h1><br />";
  echo $pages;
  echo '<table cellpadding="5" cellspacing="5" width="100%" id="itemslist">';
  echo '<tr>';
  $i=0;
  while ($read=$mysql->fetch($q)) {
    $id=$item['id']; #*
    $title=$prep->html($item['item']); # urun adı*
    $summary=$prep->html($item['summary']); # urun özeti*
    $name=$item['name']; # urun permalink*
    $new=$item['new']; # yeni urun*
    $show_price=$item['show_price']; # fiyat goster*
    $item_active=$item['active']; # ürün aktif
    $image=$item['image']; # urun foto*
    $price=$item['price']; # fiyat*
    $info=$prep->html($item['p_info']); # fiyat açıklaması*
    $campaign=$item['campaign']; # kampanya*
    $campaign_price=$item['campaign_price']; # kampanya fiyatı*
    $item_price_active=$item['p_active']; # fiyat aktif *
    $ename=$prep->html($item['ex_name']); # kur adı*
    $exchange=$item['exchange']; # kur *
    $e_active=$item['e_active']; # kur aktif *

    // prepare item details
    $price="$price $ename +KDV";
    if (empty($image)||!file_exists('img/'.$image)) $image='template/img/noimg.png';
    else $image='img/'.$image;
    if ($new) $new='<img src="template/img/yeni.gif" />'; else $new='';
    if ($campaign_price>0&&$campaign) {
      $campaign='<img src="template/img/kampanya.gif" /><br />';
      $price="<s>$price</s> $campaign_price $ename +KDV";
    }
    else $campaign='';

    $item_link='<a href="index.php?page=item&id='.$id.'">'.$title.'</a>';
    if ($SITE_SEO) $item_link='<a href="'.$SITE_URL.'/item/'.$name.'">'.$title.'</a>';
    // -------------

    if (isAdmin()) {
      $show_price=1;
    }
    elseif (isLogged()) {
      if(!empty($item['price'])) {
        if ($show_price) {
          if ($item_price_active!='1'||$e_active!='1') $price=$_LANG['brands']['oostock'];
        }
        else $price=$_LANG['brands']['aprice'];
      }
      else $item_active=0;
    }
    else {
      if(!empty($item['price'])) {
        if ($SHOW_ITEM_PRICE==0) {
          $price='';
          $campaign='';
        }
        else {
          if ($show_price) {
            if ($item_price_active!='1'||$e_active!='1') $price=$_LANG['brands']['oostock'];
          }
          else $price=$_LANG['brands']['aprice'];
        }
      }
      else $item_active=0;
    }
    // -------------

    if (isAdmin()||$item_active=='1') {
      if (isAdmin()&&$item_active=='1') $item_active='<img src="template/img/active.gif" title="Ürün Aktif" />';
      elseif (isAdmin()&&$item_active=='0') $item_active='<img src="template/img/notactive.gif" title="Ürün Aktif Değil" />';
      else $item_active='';
      $price=trim($price);
      if ($price=='+KDV') $price=$_LANG['brands']['nhprice'];

      echo <<<html
      <td id="item-$id" class="item" width="50%">$new $item_link $item_active<br />
      <img src="$image" align="left" class="item-img" title="$title" />$summary<br /><br />
      $info<br />$campaign $price<br />
      </td>
html;
      if ($i%$ITEM_DISPLAY_COLUMN!=0) echo '</tr><tr>';
      $i++;
    }
  } // while

  echo '</tr></table>';
  echo $pages;
  if (goBack()) echo goBack();
} // if
else echo $_LANG['brands']['error1'];
?>
</p>
    </div>
<!--//div:icerik -->